package com.wxy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@ComponentScan( value="com.wxy.controller")
@EnableWebMvc
@Configuration
@Import(ExceptionHandle.class)		//添加异常处理器的配置
public class springMVC implements WebMvcConfigurer{
	@Bean
	public InternalResourceViewResolver viewResolver() {
		 InternalResourceViewResolver resolver = new InternalResourceViewResolver();
	        resolver.setPrefix("/jsp/");
	        resolver.setSuffix(".jsp");
	        return resolver;
	}
//	@Bean		//默认异常处理器
//	public SimpleMappingExceptionResolver exceptionResolver() {
//		SimpleMappingExceptionResolver simpleMappingExceptionResolver=new SimpleMappingExceptionResolver();
//		simpleMappingExceptionResolver.setDefaultErrorView("error");
//		return simpleMappingExceptionResolver;
//	}
	
	/* 使用WebMvcConfigurer实现的视图解析器 */
//	@Override
//	public void configureViewResolvers(ViewResolverRegistry registry) {
//		// TODO 自动生成的方法存根
//		InternalResourceViewResolver resolver=new InternalResourceViewResolver();
//		resolver.setPrefix("/jsp/");
//		resolver.setSuffix(".jsp");
//		registry.viewResolver(resolver);
//	}
	
	/* 拦截器 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// TODO 自动生成的方法存根
		registry.addInterceptor(new interceptor()).addPathPatterns("/**").excludePathPatterns("/test3");
		
	}
}
